Add a TotalProcessorCount API that returns the total number of logical processors on the machine - #9029
Add a TotalProcessorCount API that returns the total number of logical processors on the machine#9029andrewlock wants to merge 1 commit into
TotalProcessorCount API that returns the total number of logical processors on the machine#9029Conversation
BenchmarksBenchmark execution time: 2026-08-13 10:41:49 Comparing candidate commit 6336eb5 in PR branch Found 1 performance improvements and 1 performance regressions! Performance is the same for 70 metrics, 0 unstable metrics, 65 known flaky benchmarks, 61 flaky benchmarks without significant changes.
|
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (9029) and master. ✅ No regressions detected |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 55137ff77e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| var expectedCpus = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 3 : 4; | ||
| result.Should().Be(expectedCpus); |
There was a problem hiding this comment.
Restrict the fixed-count assertion to its CI pool
On any developer machine that does not expose exactly four CPUs (or three on macOS), this test fails even though the implementation is correct. The standard RunManagedUnitTests target runs Datadog.Trace.Tests without a CI-only filter, and [SkippableFact] does not skip anything without a Skip call, so the committed unit-test suite is unusable on common local machines and will also break on any differently sized runner; guard this assertion by the intended CI environment/pool.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Unfortunately, I don't think we have a way to do this today🤔
a774a09 to
207efa7
Compare
207efa7 to
6336eb5
Compare
Summary of changes
Adds an API that returns the total number of logical processors on a machine
Reason for change
For "reasons" (in the stacked PR, related to runtime metrics) we need the total number of processors on the machine, not the number of processors available to the process (which is given in
Environment.ProcessorCount).Implementation details
Unfortunately, we have to fall back to native APIs for all of these:
GetActiveProcessorCount/sys/devices/system/cpu/onlinesysctlbyname("hw.logicalcpu")Obviously we can cache these for the process lifetime, and we need to fail safe, so if we can't get the value, bail out.
Test coverage
Added unit tests to cover the behavior, and a CI test that asserts we get the right number - this will obviously break if we change our CI machines, but at least we rarely do that 😄